package com.gcxy.controller;


import com.gcxy.core.PageVO;
import com.gcxy.core.R;
import com.gcxy.dto.*;
import com.gcxy.dto.student.AddStudentInfoDTO;
import com.gcxy.dto.student.DeleteStudentDTO;
import com.gcxy.dto.student.StudentPageDTO;
import com.gcxy.dto.student.UpdateStudentDTO;
import com.gcxy.service.StudentService;
import com.gcxy.vo.student.StudentPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Copyright (C), 2024-2024, BUG闭退！
 * Author: Huang先森
 * Date: 2024/7/29 10:48
 * FileName: StudentController
 * Description: 学生管理
 */
@Api(tags = "学生管理")
@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    @ApiOperation("下载批量上传学生模板")
    @GetMapping("/downloadAddStudentTemplate")
    public R<?> downloadAddStudentTemplate(HttpServletResponse response){
        return studentService.downloadAddUserTemple(response);
    }

    @ApiOperation("新增学生")
    @PostMapping("insertStudent")
    public R<?> insertStudent(@RequestBody AddStudentInfoDTO addStudentInfoDTO){
        return studentService.insertStudent(addStudentInfoDTO);
    }

    @ApiOperation("更新学生信息")
    @PostMapping("/updateStudent")
    public R<?> updateStudent(@RequestBody UpdateStudentDTO updateStudentDTO){
        return studentService.updateStudent(updateStudentDTO);
    }

    @ApiOperation("删除学生信息")
    @DeleteMapping("/deleteStudent")
    public R<?> deleteStudent(@RequestBody DeleteStudentDTO deleteStudentDTO){
        return studentService.deleteStudent(deleteStudentDTO);
    }

    @ApiOperation("根据条件分页查询所有学生")
    @GetMapping("/getStudentPageByCondition")
    public R<PageVO<StudentPageVO>> getStudentPageByCondition(@Validated StudentPageDTO studentPageDTO){
        return studentService.getStudentPageByCondition(studentPageDTO);
    }

    @ApiOperation(value = "批量导入学生Excel数据")
    @PostMapping("batchImportStudents")
    public R<?> batchImportStudents(@Validated BatchImportDTO batchImportDTO, HttpServletRequest request, HttpServletResponse response) throws IOException {
        return studentService.batchImportStudents(batchImportDTO, request, response);
    }
}
